package com.seal.yoyoshop.web;

import com.seal.yoyoshop.bin.Order;
import com.seal.yoyoshop.bin.Type;
import com.seal.yoyoshop.bin.User;
import com.seal.yoyoshop.service.OrderService;
import com.seal.yoyoshop.service.TypeService;
import com.seal.yoyoshop.service.impl.OrderServiceImpl;
import com.seal.yoyoshop.service.impl.TypeServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ToPayServlet", value = "/index/topay")
public class ToPayServlet extends HttpServlet {

    private OrderService orderService = new OrderServiceImpl();
    private TypeService typeService = new TypeServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        if (user == null) {
            response.sendRedirect("login");
        }
        String orderIdstr = request.getParameter("orderid");
        int orderId = Integer.parseInt(orderIdstr);
        Order order = orderService.getOrderById(orderId);
        request.setAttribute("order",order);
        List<Type> typeList = typeService.getTypeList();
        request.setAttribute("typeList",typeList);

        request.getRequestDispatcher("/index/pay.jsp").forward(request,response);
    }

}
